const CompressionWebpackPlugin = require('compression-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');
const projectRoot = process.cwd();

const plugins = [];

if (process.env.NODE_ENV === 'production') {
    plugins.push(new CompressionWebpackPlugin({
        test: /\.js$|\.html$|\.css$|\.ttf$|\.png$|\.jpg$/,
        deleteOriginalAssets: false,
        threshold: 10240
    }))
}

module.exports = {
    publicPath: "./",
    lintOnSave: true,
    productionSourceMap: false,
    devServer: {
        proxy: {
            '/api': {
                target: 'https://192.168.13.64:8080/',
                pathRewrite: { '^/api': '' },
                changeOrigin: true,
            }
        }
    },
    css: {
        loaderOptions: {
            less: {
                javascriptEnabled: true
            }
        }
    },
    runtimeCompiler: true,
    pluginOptions: {
        "style-resources-loader": {
            preProcessor: "less",
            patterns: []
        }
    },
    configureWebpack: {
        module: {
            rules: [
                {
                    test: /\.d\.md/,
                    loaders: ["vue-loader", "markdown-to-vue-loader"]
                }
            ]
        },
        plugins: [
            new CopyPlugin([
                { from: './static', to: path.join(projectRoot, 'dist') },
            ]),
        ]
    }
};
